<template>
    <h3 style="text-align: :center;">添加理财信息</h3>
    <table>
        <tr>
            <td>理财名称</td>
            <td>
                <input type="text" v-model="F_Name" />
            </td>
        </tr>
        <tr>
            <td>年收益</td>
            <td>
                <input type="text" v-model="F_APY" />
            </td>
        </tr>
        <tr>
            <td>最低金额</td>
            <td>
                <input type="text" v-model="F_MinMoney" />
            </td>
        </tr>
        <tr>
            <td>风险等级</td>
            <td>
                <input type="radio" name="fLevel" value="0" v-model="F_Level" />低风险
                <input type="radio" name="fLevel" value="1" v-model="F_Level" />中风险
                <input type="radio" name="fLevel" value="2" v-model="F_Level" />高风险
            </td>
        </tr>
        <tr>
            <td>利息</td>
            <td>
                <select v-model="I_Id">
                    <option v-for="item in Idata" :value="item.I_Id">{{ item.I_Year }}年利息{{ item.I_Interest }}</option>
                </select>
            </td>
        </tr>
        <tr>
            <td colspan="2" style="text-align:center">
                <input type="button" value="添加" class="btn btn-success" @click="SaveData" />
            </td>
        </tr>
    </table>
</template>
<script setup lang="ts">
import 'bootstrap/dist/css/bootstrap.min.css'
import 'bootstrap/dist/js/bootstrap.min.js'
import { ref, onMounted } from 'vue'
import axios from 'axios'

const F_Name = ref('')
const F_APY = ref('')
const F_MinMoney = ref('')
const F_Level = ref('0')
const I_Id = ref(1)



//加载下列列表
const Idata = ref([]);
onMounted(() => {
    axios.get('https://localhost:44305/api/Finans/ShowInterest')
        .then(res => {
            console.log(res.data)
            Idata.value = res.data;
        })

})


//保存数据
const SaveData = () => {
    //数据非空验证
    if (!F_Name.value) {
        alert('理财名称不能为空！');
        return;
    }
    if (!F_APY.value) {
        alert('年收益不能为空！');
        return;
    }
    //判断最低金额取值
    if (F_MinMoney.value < 1000) {
        alert('理财金额必须大于1000元');
        return;
    }

    axios.post('https://localhost:44305/api/Finans/AddFinancingInfo',
        {
            F_Name: F_Name.value,
            F_APY: F_APY.value,
            F_MinMoney: F_MinMoney.value,
            F_Level: F_Level.value,
            I_Id: I_Id.value
        })
        .then(res => {
            if (res.data > 0) {
                alert('理财信息添加成功');
                return;
            }
            else {
                alert('理财信息添加失败');
                return;
            }
        })
}

</script>